// dao/userDao.js
// ʵ����MySQL����
var mysql = require('mysql');
var $conf = require('../../conf/db');
var $util = require('../utils/util');
var $sql = require('../mapping/admitSqlMapping');

// ʹ�����ӳأ���������
var pool  = mysql.createPool($util.extend({}, $conf.mysql));


module.exports = {
    queryAll:function (req, res, callback) {
        pool.getConnection(function(err, connection) {
            connection.query($sql.queryAll, [], function(err, result) {
                if(result.length>=1) {
                    result = {
                        code: 200,
                        content:result
                    };
                    callback(result);
                }else{
                    callback("no");
                }
                // �ͷ�����
                connection.release();
            });
        });
    },
    //insert: function (req, detailId, callback) {
    //    var param = req.query || req.params;
    //    $util.queryHelper(req,$sql.insertInvite, [param.id],  pool,function (result) {
    //        callback(result);
    //    })
    //},

    insertInvite: function (req,res,temp, callback) {
        var param = req.query || req.params;
        $util.queryHelper(req,$sql.insertInvite, [temp,param.activeId,1],  pool,function (result) {
            callback(result);
        })
    },
    applyActive: function (req, userInfoId,activeId,activeDetailId,status ,callback) {
        $util.queryHelper(req,$sql.insertInvite, [userInfoId,activeId,status],  pool,function (result) {
            callback(result,activeDetailId);
        })
    },

    cancelInvited:function( req , callback ){
        $util.queryHelper(req,$sql.cancelInvited, req.param('id'),  pool,function (result) {
            callback(result);
        })
    }


};